import api from "../../api/api";
import { useRouter } from "vue-router";
export function permissionList(authorityCode) {
  return new Promise(function (resolve, reject) {
    let list = [];
    var userinfo = localStorage.getItem("userInfo");
    var info = JSON.parse(userinfo);
    for (var i = 0; i < info.permissionList.length; i++) {
      if (authorityCode == info.permissionList[i]) {
        // console.log(authorityCode)
        // console.log(info.permissionList[i])
        resolve(true);
        break;
      }
    }
  });
}
export function userinfo() {
  return new Promise(function (resolve, reject) {
    api
      .postFormAPI("auth/user/info", {})
      .then((res) => {
        if (res.data.code == 1) {
          var info = res.data.data;
          for (var i = 0; i < info.projectList.length; i++) {
            if (info.projectList[i].id != localStorage.getItem("projectId")) {
              localStorage.setItem(
                "projectName",
                info.projectList[i].projectName
              );
              localStorage.setItem("logoImg", info.projectList[i].logoImg);
              localStorage.setItem("projectId", info.projectList[i].id);
            }
          }
          resolve(res.data.data);
        } else {
          ElMessage.error(res.data.message);
        }
      })
      .catch((err) => { });
  });
}

export function PermissionsPage(permissionList) {
  let url = "";
  if (permissionList && permissionList.length > 0) {
    for (var i = 0; i < permissionList.length; i++) {
      // 首页A
      if (permissionList[i] == "INDEXB_VIEW") {
        url = "homepage";
        break;
      } else if (permissionList[i] == "INDEX_VIEW") {
        // 首页B
        url = "dashboard";
        break;
      } else if (permissionList[i] == "DEVICEALARM_VIEW") {
        // 报警管理
        url = "alarmMgt";
        break;
      } else if (permissionList[i] == "DTTDEVICE_VIEW") {
        // 单位设备管理
        url = "unit_equipment";
        break;
      } else if (permissionList[i] == "DEVICE_REGION_VIEW") {
        // 房间设备管理
        url = "roomMgt";
        break;
      } else if (permissionList[i] == "MONITOR_VIEW") {
        // 在线监测装置
        url = "online_device";
        break;
      } else if (permissionList[i] == "ARCFAULT_VIEW") {
        // 故障电弧装置
        url = "fault_detector";
        break;
      } else if (permissionList[i] == "ARCEXTINGUISHING_VIEW") {
        // 灭弧装置
        url = "csa_device";
        break;
      } else if (permissionList[i] == "DEVICE_VIEW") {
        // 智能断路器
        url = "electric_eqt";
        break;
      } else if (permissionList[i] == "BINDRTU_VIEW") {
        // 智慧主机管理
        url = "wisdom_host";
        break;
      } else if (permissionList[i] == "RTU_VIEW") {
        // 智慧主机库
        url = "host_library";
        break;
      } else if (permissionList[i] == "AIR_MANAGE_VIEW") {
        // 空调管理
        url = "airConditioner";
        break;
      } else if (permissionList[i] == "AIR_ALL_VIEW") {
        // 空调库
        url = "AirConditioner_library";
        break;
      } else if (permissionList[i] == "REPAIR_VIEW") {
        // 报修
        url = "repair_list";
        break;
      } else if (permissionList[i] == "ACCOUNTAUTH_VIEW") {
        // 用户信息管理
        url = "userInfoMgt";
        break;
      } else if (permissionList[i] == "ACCOUNT_VIEW") {
        // 用户管理
        url = "userMgt";
        break;
      } else if (permissionList[i] == "ACCOUNTROOM_VIEW") {
        // 房间管理
        url = "userRoomMgt";
        break;
      } else if (permissionList[i] == "RECHARGE_VIEW") {
        // 充值缴费报表
        url = "payment_report";
        break;
      } else if (permissionList[i] == "PRICECHANGE_VIEW") {
        // 电价修改报表
        url = "electrovalence";
        break;
      } else if (permissionList[i] == "ALARM_SUM_VIEW") {
        //用电设备报警报表
        url = "policeReport";
        break;
      } else if (permissionList[i] == "RECHARGESET_VIEW") {
        // 充值套餐管理
        url = "packageMgt";
        break;
      } else if (permissionList[i] == "AREA_VIEW") {
        // 场所管理
        url = "sortmgt";
        break;
      } else if (permissionList[i] == "BUILDING_VIEW") {
        // 单位管理
        url = "build_ridgepole";
        break;
      } else if (permissionList[i] == "REGIONTYPE_VIEW") {
        // 房间类型
        url = "room_type";
        break;
      } else if (permissionList[i] == "TIMERULE_ALL_VIEW") {
        // 时控规则管理
        url = "controlRules";
        break;
      } else if (permissionList[i] == "DEVCONFIG_VIEW") {
        // 配置报警参数
        url = "alarm_configuration";
        break;
      } else if (permissionList[i] == "DATASUM_VIEW") {
        // 统计分析
        url = "statisticAnalysis";
        break;
      } else if (permissionList[i] == "FEEDBACK_VIEW") {
        // 意见反馈
        url = "feedback";
        break;
      } else if (permissionList[i] == "PROJECT_MANAGE_VIEW") {
        // 项目管理
        url = "projectmgt";
        break;
      } else if (permissionList[i] == "SYSUSER_VIEW") {
        // 账号管理
        url = "accout_mgt";
        break;
      } else if (permissionList[i] == "SYSROLE_VIEW") {
        // 角色管理
        url = "role_mgt";
        break;
      } else if (permissionList[i] == "SYSMENU_VIEW") {
        // 菜单管理
        url = "menu_mgt";
        break;
      } else if (permissionList[i] == "DICTIONARY_VIEW") {
        // 字典管理
        url = "dictionary_mgt";
        break;
      } else if (permissionList[i] == "MSGMANAGER_VIEW") {
        // 消息管理
        url = "messageMgt";
        break;
      } else if (permissionList[i] == "REFUND_VIEW") {
        // 退款管理
        url = "refund";
        break;
      } else {
        url = "user";
      }
    }
  }
  return url;
}
